//*** This code is copyright 2003 by Gavin Kistner, gavin@refinery.com
//*** It is covered under the license viewable at http://phrogz.net/JS/_ReuseLicense.txt
//*** Reuse or modification is free provided you abide by the terms of that license.
//*** (Including the first two lines above in your source code satisfies the conditions.)

function UL2Menu_ShowHead(){
	var li=this;
	AddClass(li,'active');
	var xy=FindXYWH(li);
	if (li.isTop){
		li.sub.style.left=(xy.x+(!li.isHorizontal?xy.w:0))+'px';
		li.sub.style.top=(xy.y+(li.isHorizontal?xy.h:0)-(li.isTop?0:1))+'px';
	} else {
		li.sub.style.left=li.offsetWidth+'px';
		li.sub.style.top=li.offsetTop+'px';
	}
	li.sub.style.visibility='visible';
}
function UL2Menu_HideHead(){
	var li=this;
	li.sub.style.visibility='hidden';
	KillClass(li,'active');
}
function UL2Menu_ConvertMenu(){
	var menu=document.getElementById('menu');
	if (!menu) return;
	var menuIsHorizontal=HasClass(menu,'horizontal');
	var lis = menu.getElementsByTagName('li');
	for (var i=0,len=lis.length;i<len;i++){
		var li=lis[i];
		var uls = li.getElementsByTagName('ul');
		if (!uls || uls.length==0) continue;
		var ul=uls[0];
		li.sub=ul;
		li.onmouseover=UL2Menu_ShowHead;
		li.onmouseout=UL2Menu_HideHead;
		li.isTop = li.parentNode==menu;
		li.isHorizontal = (menuIsHorizontal && li.isTop);

		if (li.addedArrow || li.isTop) continue;
		var arrow=document.createElement('span');
		arrow.innerHTML='&nbsp;&rArr;';
		var a = li.getElementsByTagName('a');
		if (a && a.length>0 && a[0].parentNode==li) a[0].innerHTML+='&nbsp;&rArr;';
		else li.insertBefore(arrow,li.childNodes[1]);
		li.addedArrow=true;
	}
}

AttachEvent(window,'load',UL2Menu_ConvertMenu,true);


//***Generic Library Functions Follow
	function FindXY(obj){
		var x=0,y=0;
		while (obj){
			x+=obj.offsetLeft - (obj.scrollLeft || 0);
			y+=obj.offsetTop - (obj.scrollTop || 0);
			obj=null;
		}
		return {x:x,y:y};
	}

	function FindXYWH(obj){
		if (!obj) return { x:0, y:0, w:0, h:0 };
		var objXY = FindXY(obj);
		return { x:objXY.x, y:objXY.y, w:obj.offsetWidth||0, h:obj.offsetHeight||0 };
	}

	function AttachEvent(obj,evt,fnc,useCapture){
		if (obj.addEventListener){
			obj.addEventListener(evt,fnc,useCapture);
			return true;
		} else if (obj.attachEvent) return obj.attachEvent("on"+evt,fnc);
		else obj['on'+evt]=fnc;
		return true;
	}

	function HasClass(obj,cName){ return (!obj || !obj.className)?false:(new RegExp("\\b"+cName+"\\b")).test(obj.className) }
	function AddClass(obj,cName){ if (!obj) return; if (obj.className==null) obj.className=''; return obj.className+=(obj.className.length>0?' ':'')+cName; }
	function KillClass(obj,cName){ if (!obj) return; return obj.className=obj.className.replace(RegExp("^"+cName+"\\b\\s*|\\s*\\b"+cName+"\\b",'g'),''); }
